var ns;
app = new Vue({
    el: '#app',
    data: {
        form: {
            ID: 0,
            keywords:'',
            pageindex: 0,
            pagesize: 10,
        },
        selectlist:[],
        logCategoryList:[],
        SortList:[
            {sortid:0, sortitle:'全部', isActive:false, sortpic:'../image/icon/quanbu.png'},
            {sortid:1, sortitle:'客服工单', isActive:false, sortpic:'../image/icon/kefu.png'},
            {sortid:2, sortitle:'投诉建议', isActive:false, sortpic:'../image/icon/tousu.png'},
            {sortid:3, sortitle:'设备',isActive:false, sortpic:'../image/icon/shebei.png'},
            {sortid:4, sortitle:'安防',isActive:false, sortpic:'../image/icon/anfang.png'},
            {sortid:5, sortitle:'保洁',isActive:false, sortpic:'../image/icon/huanjing.png'},
            {sortid:9, sortitle:'通知',isActive:false, sortpic:'../image/icon/tongzhi.png'},
            {sortid:10, sortitle:'维保',isActive:false, sortpic:'../image/icon/shebei.png'},
            {sortid:20, sortitle:'审核',isActive:false, sortpic:'../image/icon/shenhe.png'},
            // {sortid:21, sortitle:'内部通知',isActive:false, sortpic:'../image/icon/neibutongzhi.png'},
        ],
        PlanType: 4,
        isShow:true,
        showsearch:false,
        listdata:[],
        wintitle:'',//查看更多的弹窗title
    },
    methods: {
        get_data: function() {
            var that = this;
            var options = {};
            options.keywords = that.form.keywords;
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.action = "wechatmsgsearch";
            console.log(JSON.stringify(options));
            ns.post(options, function(succeed, data, err) {
                console.log(JSON.stringify(data));
                console.log(JSON.stringify(err));
                if (succeed) {
                    that.selectlist = data.data;
                    if (data.data.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.selectlist = data.data;
                    } else {
                        that.selectlist = that.tongzhilist.concat(data.data);
                    }

                    app.current_item_length = that.selectlist.length;
                    for (var i = 0; i < data.data.length; i++) {
                        data.data[i].AddTime = ns.SetTime_style(data.data[i].AddTime);
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_openDetail:function(id){
            var that=this;
            ns.openWin('tongzhixiaoxidetail_frm', '消息详情', {
                id: id
            });
            api.sendEvent({
                name: 'isreadtrue',
                extra: {
                    key1: 'value1'
                }
            });
        },
        choosepart: function(item) {
            var that=this;
            item.isActive=!item.isActive;
            that.logCategoryList=[];
            if(item.sortid>0){
                for(var i=0; i<that.SortList.length;i++){
                    if(that.SortList[i].isActive==true){
                        that.logCategoryList.push(that.SortList[i].sortid);
                    }
                }  
            }else{
               if(item.isActive==true){
                    for(var i=0; i<that.SortList.length;i++){
                        that.SortList[i].isActive=true;
                        that.logCategoryList.push(that.SortList[i].sortid);
                    }
               }else{
                for(var i=0; i<that.SortList.length;i++){
                    that.SortList[i].isActive=false;
                }
                that.logCategoryList=[];
               }
            }   
            // that.get_data();
        },
        do_search: function () {
            var that=this;
            that.isShow=false;
            this.get_data();
        },
        clear_searchVal: function () {
            var that = this;
            that.isShow=true;
            // document.getElementById("search-input").value = '';
            that.logCategoryList=[];
        },
        do_start: function() {
            var that = this;
            var options = {};
            options.ID = that.form.ID;
            options.action = "startequipmentplan";
            ns.post(options, function(succeed, data, err) {
                that.reload_list();
                ns.openWin('bjlh_list_frm', '任务开始', {
                    id: that.form.ID
                });
            });
        },
        do_open_more:function(item){
            var that=this;
            that.showsearch=true;
            that.wintitle=item.title;
            that.listdata=[];
            that.listdata=item.list;
        },
        doHideSearch:function(){
            var that=this;
            that.showsearch=false;
        },
        do_open_list:function(item){
            // .logCategory,item2.JpushLogID
            console.log(item);
            var that=this;
            if(item.logCategory==1){
                title="客服工单";
                ns.openWin('home_task_con_frm',title,{
                    IsWorkOrder:1,
                    servicetype:1,
                    id:item.ID,
                });
                return;
            }
            if(item.logCategory==2){
                title="投诉建议";
                ns.openWin('home_task_con_frm',title,{
                    IsWorkOrder:2,
                    servicetype:2,
                    id:item.ID,
                });
                return;
            }
            if(item.logCategory==3){
                title="设备巡检";
                ns.openWin('equipment_list_frm',title,{
                    id:item.ID,
                });
                return;
            }
            if(item.logCategory==10){
                title="设备维保";
                ns.openWin('equipment_list_frm',title,{
                    id:item.ID
                });
                return;
            }
            if(item.logCategory==4){
                title="安防巡更";
                 ns.openWin('patrolplan_list_frm_new',title,{
                    id:item.ID
                });
                // ns.openWin('patrolplan_list_frm',title,{
                //     id:item.ID
                // });
                return;
            }
            if(item.logCategory==5){
                title="保洁绿化";
                ns.openWin('bjlh_list_frm',title,{
                    id:item.ID
                });
                return;
            }
            if(item.logCategory==9){
                title="通知公告";
                ns.openWin('tongzhigonggao_typelist',title,{
                    ID:item.ID
                });
                return;
            }
            if(item.logCategory==20){
                if(item.Type==18||item.Type==19||item.Type==20){
                    ns.openWin('examine_detail_hetong', '合同详情', {
                        ApprovalID: item.ID,
                        Type:item.Type
                    });
    
                }else if(item.Type==21||item.Type==22||item.Type==23||item.Type==24||item.Type==25||item.Type==26||item.Type==27||item.Type==28||item.Type==29||item.Type==30){
                    ns.openWin('examine_detail_yg_bangong', '审批详情', {
                        ApprovalID: item.ID,
                        Type:item.Type
                    });
                }
                else{
                    ns.openWin('examine_detail', '审批详情', {
                        ApprovalID: item.ID,
                        Type:item.Type
                    });
    
                }
                return;
            }
            // if(categoryid==21){
            //     title="内部通知";
            //     ns.openWin('neibutz_typelist',title,{
            //         ID:ID
            //     });
            //     return;
            // }     
        }
    }
});
ns = window.Foresight.Util;
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.form.ID = api.pageParam.id || 0;
    ns.init_search();
    // setTimeout(function() {
    //     app.get_data();
    // }, 500)
};
ns.init_search();
